package com.hsteach.web.controller.patrol.sdk;

import com.hsteach.common.annotation.Anonymous;
import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.service.buildingApply.BuildingApplySdkService;
import com.hsteach.service.patrol.InspectionService;
import com.hsteach.web.controller.buildingApply.sdk.dto.SumApplyDto;
import com.hsteach.web.controller.buildingApply.sdk.vo.SumApplyVo;
import com.hsteach.web.controller.patrol.dto.QueryInspectionDTO;
import com.hsteach.web.controller.patrol.sdk.dto.SumEventDto;
import com.hsteach.web.controller.patrol.sdk.vo.SumEventVo;
import com.hsteach.web.controller.patrol.vo.InspectionDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.time.YearMonth;
import java.util.List;

/**
 * 巡查事件外部接口
 *
 * @author fanxquer
 * @date 2023-07-07
 */
@Api(value = "巡查事件外部接口", tags = "巡查事件外部接口")
@RestController
@RequestMapping("/sdk/patrol/event")
public class PatrolSdkController extends BaseController {

    @Autowired
    public InspectionService inspectionService;

    /**
     * 查询当月巡查事件总数
     */
    @ApiOperation("查询当月巡查事件总数")
    @Anonymous
    @PostMapping("/sumEvent")
    public AjaxResult sumEvent(HttpServletRequest request, @RequestBody @Validated SumEventDto dto) {
        QueryInspectionDTO queryInspectionDTO =new QueryInspectionDTO();
        // 获取当前日期
        LocalDate currentDate = LocalDate.now();

       // 获取当前月份的第一天
        LocalDate firstDayOfMonth = currentDate.withDayOfMonth(1);
        queryInspectionDTO.setStartTime(firstDayOfMonth.toString());

        // 获取当前月份的最后一天
        YearMonth currentYearMonth = YearMonth.from(currentDate);
        LocalDate lastDayOfMonth = currentYearMonth.atEndOfMonth();
        queryInspectionDTO.setEndTime(lastDayOfMonth.toString());
        queryInspectionDTO.setPageNum(1);
        queryInspectionDTO.setPageSize(10);
        queryInspectionDTO.setOrgCode(dto.getOrgCode());
        TableDataInfo<InspectionDetailVO> list = inspectionService.list(queryInspectionDTO);

        SumEventVo vo = new SumEventVo();
        vo.setSumRet(list.getTotal());
        return AjaxResult.success(vo);
    }

}
